var time_utils = require("./time_utils");
var files_logger = {
  get_file_name() {
    return time_utils.str("YYYY-MM-DD") + "/" + time_utils.str("HH-mm-ss");
  },
  write(app_name, action_name, text, file_name) {
    file_name = file_name || this.get_file_name();
    var path =
      "/sdcard/aaaaaaautojs-logger/" +
      app_name +
      "/" +
      action_name +
      "/" +
      file_name +
      ".txt";
    files.createWithDirs(path);
    files.write(path, text);
  },
  append(logger_name, action_name, text, file_name) {
    file_name = file_name || this.get_file_name();
    var path =
      "/sdcard/aaaaaaautojs-logger/" +
      logger_name +
      "/" +
      (action_name ? action_name + "/" : "") +
      file_name +
      ".txt";
    files.createWithDirs(path);
    files.append(path, text);
  },
  app_start_logger(app_name, content) {
    var logger_name = "app_start_logger";
    var action_name = null;
    var text =
      content ||
      time_utils.str("YYYY-MM-DD HH:mm:ss") + "  " + app_name + " 启动\n";
    var file_name = time_utils.str("YYYY-MM-DD");
    console.log("files_logger app_start_logger: ", text);
    this.append(logger_name, action_name, text, file_name);
  },
};
module.exports = files_logger;
